package at.jaki.ubb.crawling.demo.core;

import java.io.File;
import java.util.Collection;

import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

import at.jaki.ubb.crawling.api.CrawlingEngine;
import at.jaki.ubb.crawling.core.CrawlingEngineImpl;
import at.jaki.ubb.crawling.demo.dataFinder.KeplerWebfinder;
import at.jaki.ubb.crawling.demo.db.FsDataBase;
import at.jaki.ubb.crawling.demo.ui.UiManager;
import at.jaki.ubb.crawling.model.Target;

public class Core {
	
	private static final Logger LOG = Logger.getLogger(Core.class);

	public static final String LOG4J = "config" + File.separatorChar + "log4j.xml";

	private static void initLog4j() {
		String log4j = LOG4J;
		DOMConfigurator.configure(log4j);
		LOG.info("Loaded log configuration from " + log4j);
	}

	public static void main(String[] args) {
		initLog4j();
		
		FsDataBase.getInstance();
		
		CrawlingEngine ce = new CrawlingEngineImpl();
		ce.start(ConfigGenerator.getConfig());

		Listener l = new Listener(ce);
		UiManager.getInstance().init(l);
		
		Collection<String> list = createExistingStarList();
		UiManager.getInstance().addStars(list);
	}

	

	private static Collection<String> createExistingStarList() {
		return FsDataBase.getInstance().getAllIds();
	}

	private static Target<String> getInitialTarget(String[] args) {
		String s = "APH52086771";
		Target<String> t = new Target<String>(1D, s, KeplerWebfinder.INPUT_TYPE, s);
		return t;
	}

}
